<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>04JS运算符</title>
</head>
<body>
<script>
  //除法会根据实际情况显示运算结果
  console.log(5/2);//2.5
  console.log(5/2.0);//2.5
  //如果比较运算符左右两边有数字，会转为数字在进行比较
  console.log(3>10);//false
  console.log(3>'10');//false
  console.log('3'>10);//false
  //如果比较运算符左右两边都是字符串，会比较它们的编码值
  console.log('3'>'10');//true
  console.log('超'>'博');//true
  console.log('3'.charCodeAt());//51
  console.log('博'.charCodeAt());//21338
  console.log('超'.charCodeAt());//36229
  console.log('3'.charCodeAt());//51
  console.log('10'.charCodeAt(0));//49
  console.log('1'.charCodeAt());//49

  //Number()将参数转换为数字，如果得不到数值类型的结果，会得到NaN（Not a Number）
  console.log(Number('3')),typeof Number('3');//3 number
  console.log(Number(true),typeof Number(true));//1 number
  console.log(Number(false),typeof Number(false));//0 number
  console.log(Number('你好'),typeof Number('你好'));//NaN number

  let a = 1;
  let b = true;
  //松散比较运算符，只比较值，Number（true）=1
  console.log(a == b);true
  //严格比较运算符，先比较类型，再比较值 number ≠ boolean
  console.log(a === b);false

  //Boolean()将参数转换为布尔值，如果参数为0 空字符串 null undefined NaN 都会转为false
  console.log(Boolean(0));//false
  console.log(Boolean(''));//false
  console.log(Boolean(null));//false
  console.log(Boolean(undefined));//false
  console.log(Boolean(NaN));//false
  console.log(Boolean('  '));//true
  console.log(Boolean('下午好！'));//true

  //三元运算符
  let c=0;
  console.log(c == 0 ? 'YES' : 'NO');//YES
  //=是赋值符号，给c赋值未0，Boolean(0)为false，所以输出NO
  console.log(c = 0 ? 'YES' : 'NO');//NO

</script>

</body>
</html>